package com.qipay.pay.impl;

import com.qipay.baas.model.Order;
import com.qipay.order.config.OrderChannelEnum;
import com.qipay.order.config.OrderStateEnum;
import com.qipay.order.service.OrderService;
import com.qipay.pay.TradeService;
import com.qipay.pay.entity.CpTradeCloseRequest;
import com.qipay.pay.entity.CpTradeQueryRequest;
import com.qipay.scalar.type.ApiResultCodeEnum;
import com.qipay.security.jwt.JWTUser;
import com.qipay.sp.SpService;
import com.qipay.sp.excutor.ExcutorFactory;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Service
public class TradeServiceImpl implements TradeService {

    @Autowired
    OrderService orderService;
    @Autowired
    SpService spService;

    @Override
    public Map<String, Object> tradeQuery(CpTradeQueryRequest entity){
        Assert.notNull(entity, "请输入交易信息");
        Assert.notNull(entity.getMchId(), "请输入商户号");
        Assert.notNull(entity.getOutTradeNo(),"请输入商户订单号");

        Order order = orderService.getByCpidAndOutTradeNo(Long.valueOf(entity.getMchId()), entity.getOutTradeNo());
        Assert.notNull(order, "找不到相应订单信息");
        Map<String, Object> result = new HashMap<>();
        result.put("mch_id", entity.getMchId());
        result.put("trade_state", OrderStateEnum.getByType(order.getState()).toString());
        result.put("total_fee", order.getAmount());
        result.put("out_trade_no", order.getOutTradeNo());
        result.put("message", OrderStateEnum.getInfo(order.getState()));
            return result;
    }

}
